<article class="module width_full">
	<header>
		<h3 class="tabs_involved">订单查看</h3>

		<ul class="tabs" name="menu1">
			<li id="li_1" class="active"><a href="javascript:select_tab('1');">基本信息</a></li>
			<li id="li_2"><a href="javascript:select_tab('2');">收款和售后</a></li>
			<li id="li_3"><a href="javascript:select_tab('3');">发货记录</a></li>
			<li id="li_4"><a href="javascript:select_tab('4');">发票和备注</a></li>
			<li id="li_5"><a href="javascript:select_tab('5');">订单日志</a></li>
			<li id="li_6"><a href="javascript:select_tab('6');">订单附言</a></li>
		</ul>
	</header>

	<div class="module_content" id="tab-1">
		<fieldset>
			<table class="tablesorter clear">
				<colgroup>
					<col width="120px" />
					<col />
				</colgroup>

				<thead>
					<tr><th colspan="2">订单信息</th></tr>
				</thead>
				<tbody>
					<tr>
						<th>订单号:</th><td>{$order_no}</td>
					</tr>
					<tr>
						<th>当前状态:</th><td>{echo:order_class::orderStatusText(order_class::getOrderStatus($this->orderRow))}</td>
					</tr>
					<tr>
						<th>支付状态:</th><td>{echo:order_class::getOrderPayStatusText($this->orderRow)}</td>
					</tr>
					<tr>
						<th>配送状态:</th><td>{echo:order_class::getOrderDistributionStatusText($this->orderRow)}</td>
					</tr>
					<tr>
						<th>订单类型:</th><td>{echo:order_class::getOrderTypeText($this->orderRow)}</td>
					</tr>
					<tr>
						<th>平台货款结算:</th><td>{if:$is_checkout == 1}已结算{else:}未结算{/if}</td>
					</tr>
				</tbody>
			</table>
		</fieldset>

		<fieldset>
			<table class="tablesorter clear">
				<colgroup>
					<col />
					<col width="85px" />
					<col width="85px" />
					<col width="85px" />
					<col width="85px" />
					<col width="155px" />
				</colgroup>

				<thead>
					<tr>
						<th>商品名称</th>
						<th>商品原价</th>
						<th>实际价格</th>
						<th>商品数量</th>
						<th>小计</th>
						<th>配送方式</th>
					</tr>
				</thead>

				<tbody>
                    {foreach:items=Api::run('getSellerOrderGoodsRowByOrderId',array('id'=>$order_id))}
					<tr>
						<td>
							{set:$goodsRow = JSON::decode($item['goods_array'])}
							<a href="{url:/site/products/id/$item['goods_id']}" target="_blank">
								{$goodsRow['name']} &nbsp;&nbsp;
								{$goodsRow['value']} &nbsp;&nbsp;
								{$goodsRow['goodsno']} &nbsp;&nbsp;
                                {foreach:items=Api::run('getBrandByGoodsId',array('id'=>$item["goods_id"])) item=$brandRow}
                                【{$brandRow['name']}】
                                {/foreach}
							</a>
						</td>
						<td>￥{$item['goods_price']}</td>
						<td>￥{$item['real_price']}</td>
						<td>{$item['goods_nums']}</td>
						<td>￥{echo:$item['real_price'] * $item['goods_nums']}</td>
						<td>
							{echo:Order_Class::goodsSendStatus($item['is_send'])}
							{if:$item['delivery_id']}
							<input class="alt_btn" type="button" onclick="freightLine({$item['delivery_id']})" value="快递跟踪" />
							{/if}
						</td>
					</tr>
					{/foreach}
				</tbody>
			</table>
		</fieldset>

		<fieldset>
			<table class="tablesorter clear">
				<colgroup>
					<col width="120px" />
					<col />
				</colgroup>

				<thead>
					<tr><th colspan="2">订单金额明细</th></tr>
				</thead>

				<tbody>
					<tr>
						<th>商品总额:</th><td>￥{$payable_amount}</td>
					</tr>
					<tr>
						<th>配送费用:</th><td>￥{$real_freight}</td>
					</tr>
					<tr>
						<th>保价费用:</th><td>￥{$insured}</td>
					</tr>
					<tr>
						<th>税金:</th><td>￥{$taxes}</td>
					</tr>
					{if:isset($prop) && $prop}
					<tr>
						<th>优惠券:</th>
                        <td>
                        {foreach:items=Api::run('getPropListAll',array('id'=>$prop))}
                        {$item['value']}
                        {/foreach}
                        </td>
					</tr>
					{/if}
					<tr>
						<th>优惠总额:</th><td>￥{$promotions}</td>
					</tr>
					<tr>
						<th>增加或减少金额:</th>
						<td>
							￥
							{if:Order_class::getOrderStatus($this->orderRow) < 3}
							<input type='text' value='{$discount}' class='tiny' onchange='updateDiscount();' name='discount' />
							{else:}
							{$discount}
							{/if}
							<label class='tip'>折扣用" - ",涨价用" + "</label>
						</td>
					</tr>
					<tr>
						<th>订单总额:</th><td>￥<span id="orderAmount">{$order_amount}</span></td>
					</tr>
					<tr>
						<th>已支付金额:</th><td>{set:$item = Api::run('getAmountRowByOrderId',array('order_id'=>$order_id))}
                        ￥{$item['amount']}</td>
					</tr>

					{set:$commissionFee=plugin::trigger('getCommissionFeeByOrderId',$order_id);}
					{if:$commissionFee}
					<tr><th>分销佣金:</th><td><a href="javascript:void(0)" onclick="art.dialog.open('{url:/seller/commission_order_user/order_id/$order_id}',{width:'50%',height:'50%'});" title="推介者信息">￥{$commissionFee}</a></td></tr>
					{/if}
				</tbody>
			</table>
		</fieldset>

		<fieldset>
			<table class="tablesorter clear">
				<colgroup>
					<col width="120px" />
					<col />
				</colgroup>
                {if:goods_class::isDelivery($goods_type)}
				<thead>
					<tr><th colspan="2">收货人信息</th></tr>
				</thead>
				<tbody>
					<tr>
						<th>发货日期:</th><td>{$send_time}</td>
					</tr>
					<tr>
						<th>姓名:</th><td>{$accept_name}</td>
					</tr>
					<tr>
						<th>电话:</th><td>{$telphone}</td>
					</tr>
					<tr>
						<th>手机 :</th><td>{$mobile}</td>
					</tr>
					<tr>
						<th>地区:</th><td>{$area_addr}</td>
					</tr>
					<tr>
						<th>地址:</th><td>{$address}</td>
					</tr>
					<tr>
						<th>邮编:</th><td>{$postcode}</td>
					</tr>
					<tr>
						<th>送货时间:</th><td>{$accept_time}</td>
					</tr>
				</tbody>
				{elseif:$goods_type == 'code'}
				<thead>
					<tr><th colspan="2">消费验证码信息</th></tr>
				</thead>
				<tbody>
					<tr>
						<th>消费验证码:</th>
						<td>
    					    {foreach:items=Api::run('getOrderCodeByOrderId',array('id' => $id)) item=$codeRow}
    					    <p>{$codeRow['code']} [{if:$codeRow['is_used']}已使用:{$codeRow['use_time']}{else:}未使用{/if}]</p>
    					    {/foreach}
    					    {if:!isset($codeRow)}付款后由系统生成{/if}
						</td>
					</tr>
				</tbody>
				{elseif:$goods_type == 'download'}
				<thead>
					<tr><th colspan="2">文件信息</th></tr>
				</thead>
				<tbody>
					<tr>
						<th>文件下载:</th>
						<td>
    					    {foreach:items=Api::run('getOrderDownloadByOrderId',array('id' => $id)) item=$downloadRow}
                            <p>[已下载：{$downloadRow['num']}/{$downloadRow['limit_num']}] 截至 {$downloadRow['end_time']} 过期</p>
    					    {/foreach}
						</td>
					</tr>
				</tbody>
				{/if}
			</table>
		</fieldset>

		<fieldset>
			<table class="tablesorter clear">
				<colgroup>
					<col width="120px" />
					<col />
				</colgroup>

				<thead>
					<tr><th colspan="2">支付和配送信息</th></tr>
				</thead>

				<tbody>
					<tr>
						<th>配送方式:</th><td>{$delivery}</td>
					</tr>

					{if:$takeself}
					<tr>
						<th>自提地址:</th>
						<td>
							{$takeself['province_str']}
							{$takeself['city_str']}
							{$takeself['area_str']}
							{$takeself['address']}
						</td>
					</tr>
					<tr>
						<th>自提联系方式:</th>
						<td>
							座机：{$takeself['phone']} &nbsp;&nbsp;
							手机：{$takeself['mobile']}
						</td>
					</tr>
					{/if}

					<tr>
						<th>商品重量:</th><td>{$goods_weight}</td>
					</tr>
					<tr>
						<th>支付方式:</th><td>{$payment}</td>
					</tr>
					<tr>
						<th>可得积分:</th><td>{$point}</td>
					</tr>
				</tbody>
			</table>
		</fieldset>
	</div>

	<div class="module_content" id="tab-2">
		<fieldset>
			<table class="tablesorter clear">
				<colgroup>
					<col width="120px" />
					<col />
				</colgroup>

				<thead>
					<tr><th colspan="2">收款单据</th></tr>
				</thead>

				<tbody>
                    {foreach:items=Api::run('getCollectionDocByOrderId',array('order_id'=>$order_id))}
					<tr>
						<th>付款时间：</th><td>{$item['time']}</td>
					</tr>
					<tr>
						<th>金额：</th><td>{$item['amount']}</td>
					</tr>
					<tr>
						<th>支付方式：</th><td>{$item['name']}</td>
					</tr>
					<tr>
						<th>付款备注：</th><td>{$item['note']}</td>
					</tr>
					<tr>
						<th>状态：</th><td>{if:$item['pay_status']==0}准备中{else:}支付完成{/if}</td>
					</tr>
					<tr><th colspan="2"></th></tr>
					{/foreach}
				</tbody>
			</table>
		</fieldset>

		<fieldset>
			<table class="tablesorter clear">
				<colgroup>
					<col width="120px" />
					<col />
				</colgroup>

				<thead>
					<tr><th colspan="2">退款单据</th></tr>
				</thead>
				<tbody>
                    {foreach:items=Api::run('getRefundmentDocByOrderId',array('order_id'=>$order_id))}
					<tr>
						<th>退款商品：</th>
						<td>
                            {foreach:items=Api::run('getOrderGoodsRowById',array('id'=>$item["order_goods_id"])) item=$orderGoodsItem key=$orderGoodsKey}
							{set:$goods = JSON::decode($orderGoodsItem['goods_array'])}
							<p><a href="{url:/site/products/id/$orderGoodsItem['goods_id']}" target="_blank" title="{$goods['name']}">{$goods['name']} X {$orderGoodsItem['goods_nums']} </a></p>
							{/foreach}
						</td>
					</tr>
					<tr>
						<th>退款金额：</th><td>{$item['amount']}</td>
					</tr>
					<tr>
						<th>申请时间：</th><td>{$item['time']}</td>
					</tr>
					<tr>
						<th>状态：</th><td>{echo:Order_Class::refundmentText($item['pay_status'])}</td>
					</tr>
					<tr>
						<th>退款理由：</th><td>{$item['content']}</td>
					</tr>
					<tr>
						<th>退款方式：</th><td>{echo:Order_Class::refundWay($item['way'])}</td>
					</tr>
					<tr><th colspan="2"></th></tr>
					{/foreach}
				</tbody>
			</table>
		</fieldset>

		<fieldset>
			<table class="tablesorter clear">
				<colgroup>
					<col width="120px" />
					<col />
				</colgroup>

				<thead>
					<tr><th colspan="2">换货单据</th></tr>
				</thead>
				<tbody>
					{foreach:items=Api::run('getExchangeDocByOrderId',array('order_id'=>$order_id))}
					<tr>
						<th colspan="2">
							{foreach:items=Api::run('getOrderGoodsRowById',array('id'=>$item["order_goods_id"])) item=$orderGoods key=$orderGoodsKey}
							{set:$goods = JSON::decode($orderGoods['goods_array'])}
							<p>
							<a href="{url:/site/products/id/$orderGoods['goods_id']}" target="_blank" title="{$goods['name']}">{echo:IString::substr($goods['name'],28)} X {$orderGoods['goods_nums']}</a>
							{if:$item['seller_id']}
							<a href="{url:/site/home/id/$item['seller_id']}" target="_blank"><i class="operator fa fa-user"></i></a>
							{/if}
							</p>
							{/foreach}
						</th>
					</tr>
					<tr>
						<th>申请时间：</th><td>{$item['time']}</td>
					</tr>
					<tr>
						<th>状态：</th><td>{echo:Order_Class::refundmentText($item['status'])}</td>
					</tr>
					<tr>
						<th>换货理由：</th><td>{$item['content']}</td>
					</tr>

					{if:$item['user_send_time']}
					<tr>
						<th>返还物流：</th>
						<td>
						    {$item['user_send_time']}
						    <p>
        				    {foreach:items=Api::run('getFreightCompanyById',array('freight_id'=>$item['user_freight_id'])) item=$tempFreight}
                            {$tempFreight['freight_name']}
                            {/foreach}

                            【快递单号：{$item['user_delivery_code']}】
                            <button class="btn btn-default btn-sm" type="button" onclick="freightLineByCode({$item['user_freight_id']},'{$item['user_delivery_code']}')">物流跟踪</button>
						    </p>
						</td>
					</tr>
					{/if}

					{if:$item['seller_send_time']}
					<tr>
						<th>重发物流：</th>
						<td>
						    {$item['seller_send_time']}
						    <p>
        				    {foreach:items=Api::run('getFreightCompanyById',array('freight_id'=>$item['seller_freight_id'])) item=$tempFreight}
                            {$tempFreight['freight_name']}
                            {/foreach}

                            【快递单号：{$item['seller_delivery_code']}】
                            <button class="btn btn-default btn-sm" type="button" onclick="freightLineByCode({$item['seller_freight_id']},'{$item['seller_delivery_code']}')">物流跟踪</button>
						    </p>
						</td>
					</tr>
					{/if}

					<tr><th colspan="2"></th></tr>
					{/foreach}
				</tbody>
			</table>
		</fieldset>

		<fieldset>
			<table class="tablesorter clear">
				<colgroup>
					<col width="120px" />
					<col />
				</colgroup>

				<thead>
					<tr><th colspan="2">维修单据</th></tr>
				</thead>
				<tbody>
					{foreach:items=Api::run('getFixDocByOrderId',array('order_id'=>$order_id))}
					<tr>
						<th colspan="2">
							{foreach:items=Api::run('getOrderGoodsRowById',array('id'=>$item["order_goods_id"])) item=$orderGoods key=$orderGoodsKey}
							{set:$goods = JSON::decode($orderGoods['goods_array'])}
							<p>
							<a href="{url:/site/products/id/$orderGoods['goods_id']}" target="_blank" title="{$goods['name']}">{echo:IString::substr($goods['name'],28)} X {$orderGoods['goods_nums']}</a>
							{if:$item['seller_id']}
							<a href="{url:/site/home/id/$item['seller_id']}" target="_blank"><i class="operator fa fa-user"></i></a>
							{/if}
							</p>
							{/foreach}
						</th>
					</tr>
					<tr>
						<th>申请时间：</th><td>{$item['time']}</td>
					</tr>
					<tr>
						<th>状态：</th><td>{echo:Order_Class::refundmentText($item['status'])}</td>
					</tr>
					<tr>
						<th>换货理由：</th><td>{$item['content']}</td>
					</tr>

					{if:$item['user_send_time']}
					<tr>
						<th>返还物流：</th>
						<td>
						    {$item['user_send_time']}
						    <p>
        				    {foreach:items=Api::run('getFreightCompanyById',array('freight_id'=>$item['user_freight_id'])) item=$tempFreight}
                            {$tempFreight['freight_name']}
                            {/foreach}

                            【快递单号：{$item['user_delivery_code']}】
                            <button class="btn btn-default btn-sm" type="button" onclick="freightLineByCode({$item['user_freight_id']},'{$item['user_delivery_code']}')">物流跟踪</button>
						    </p>
						</td>
					</tr>
					{/if}

					{if:$item['seller_send_time']}
					<tr>
						<th>重发物流：</th>
						<td>
						    {$item['seller_send_time']}
						    <p>
        				    {foreach:items=Api::run('getFreightCompanyById',array('freight_id'=>$item['seller_freight_id'])) item=$tempFreight}
                            {$tempFreight['freight_name']}
                            {/foreach}

                            【快递单号：{$item['seller_delivery_code']}】
                            <button class="btn btn-default btn-sm" type="button" onclick="freightLineByCode({$item['seller_freight_id']},'{$item['seller_delivery_code']}')">物流跟踪</button>
						    </p>
						</td>
					</tr>
					{/if}

					<tr><th colspan="2"></th></tr>
					{/foreach}
				</tbody>
			</table>
		</fieldset>
	</div>

	<div class="module_content" id="tab-3">
		<fieldset>
			<table class="tablesorter clear">
				<colgroup>
					<col width="150px" />
					<col width="120px" />
					<col width="120px" />
					<col width="150px" />
					<col width="150px" />
					<col />
				</colgroup>

				<thead>
					<tr>
						<th>配送时间</th>
						<th>配送方式</th>
						<th>物流公司</th>
						<th>物流单号</th>
						<th>收件人</th>
						<th>备注</th>
					</tr>
				</thead>

				<tbody>
                    {foreach:items=Api::run('getDeliveryDocByOrderId',array('order_id'=>$order_id))}
					<tr>
						<td>{$item['time']}</td>
						<td>{$item['pname']}</td>
						<td>
						    {foreach:items=Api::run('getFreightCompanyById',array('freight_id'=>$item["freight_id"])) item=$tempFreight key=$tempFreightKey}
                            {$tempFreight['freight_name']}
                            {/foreach}
                        </td>
						<td>{$item['delivery_code']}</td>
						<td>{$item['name']}</td>
						<td>{$item['note']}</td>
					</tr>
					{/foreach}
				</tbody>
			</table>
		</fieldset>
	</div>

	<div class="module_content" id="tab-4">
		<form action="{url:/seller/order_note}" method="post">
		<input type="hidden" name="order_id" value="{$order_id}"/>
		<fieldset>
			<label>是否开票：</label>
			{if:$invoice==0}否{else:}是{/if}
		</fieldset>

		<fieldset>
		<label>发票信息：</label>
		{echo:CountSum::invoiceText($invoice_info)}
		</fieldset>

		<fieldset>
			<label>订单备注</label>
			<textarea name="note" rows="8" cols="100">{$note}</textarea>

			<div class="submit_link">
				<input type="submit" class="alt_btn" value="确 定" />
				<input type="reset" value="重 置" />
			</div>
		</fieldset>
		</form>
	</div>

	<div class="module_content" id="tab-5">
		<fieldset>
			<table class="tablesorter clear">
				<colgroup>
					<col width="200px">
					<col width="150px">
					<col width="150px">
					<col width="100px">
					<col />
				</colgroup>
				<thead>
					<tr>
						<th>时间</th>
						<th>操作人</th>
						<th>动作</th>
						<th>结果</th>
						<th>备注</th>
					</tr>
				</thead>
				<tbody>
                    {foreach:items=Api::run('getOrderLogByOrderId',array('order_id'=>$order_id))}
					<tr>
						<td>{$item['addtime']}</td>
						<td>{$item['user']}</td>
						<td>{$item['action']}</td>
						<td>{$item['result']}</td>
						<td>{$item['note']}</td>
					</tr>
					{/foreach}
				</tbody>
			</table>
		</fieldset>
	</div>

	<div class="module_content" id="tab-6">
		<fieldset>
			<label>订单附言</label>
			<div class="box">{$postscript}</div>
		</fieldset>
	</div>
</article>

<script type='text/javascript'>

var pay_status = '{$pay_status}';

//DOM加载完毕后运行
$(function()
{
	select_tab(1);
});

//选择当前Tab
function select_tab(curr_tab)
{
	$("div.module_content").hide();
	$("#tab-"+curr_tab).show();
	$("ul[name=menu1] > li").removeClass('active');
	$('#li_'+curr_tab).addClass('active');
}

//快递跟踪
function freightLine(doc_id)
{
	var urlVal = "{url:/block/freight/id/@id@}";
	urlVal = urlVal.replace("@id@",doc_id);
	art.dialog.open(urlVal,{title:'轨迹查询',width:'600px',height:'500px'});
}

//快递跟踪
function freightLineByCode(doc_id,code)
{
	var urlVal = "{url:/block/freight/id/@id@/code/@code@}";
	urlVal = urlVal.replace("@id@",doc_id).replace("@code@",code);
	art.dialog.open(urlVal,{title:'轨迹查询',width:'600px',height:'500px'});
}

//修改订单价格
function updateDiscount()
{
	var order_id = {$id};
	var discount = $('input[name="discount"]').val();
	$.getJSON("{url:/seller/order_discount}",{'order_id':order_id,'discount':discount},function(json)
	{
		if(json.result == true)
		{
			tips('价格修改成功');
			$('#orderAmount').text(json.orderAmount);
			$('#orderAmount').addClass("red");
			return;
		}
		var message = json.message ? json.message : '价格修改失败';
		tips(message);
	});
}
</script>
